<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-resource-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${resource.id}" />
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单类型：</label>
            <div class="col-sm-8">
                <label> <input type="radio" name="type" value="0" /> 目录 </label>
                <label> <input type="radio" name="type" value="1" checked="checked" /> 菜单 </label>
                <label> <input type="radio" name="type" value="2" /> 按钮 </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">资源名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" id="name" required="required"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级菜单：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" onclick="selectResourceTree()" id="treeName" readonly="true" required="required" th:value="${resource.name}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="priority" id="priority" required="required"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">图标：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="icon" id="icon"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单状态：</label>
            <div class="col-sm-8">
                <label> <input type="radio" name="status" value="1" id="status" checked="checked" /> 有效 </label>
                <label> <input type="radio" name="status" value="2"  id="status" /> 无效 </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">权限访问路径：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="url" id="url" required="required"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">权限标识：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="permission" id="permission" required="required"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">资源描述：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="description" id="description"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">(默认自动获取)uuid：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="resourceId" id="resourceId"/>
            </div>
        </div>
    </form>
</div>
<script>
    function submitHandler() {
        if ($.validate.form()) {
            debugger;
            $.operate.save(ctx + "resource/add", $('#form-resource-add').serialize());
        }
    }
    /*菜单管理-新增-选择菜单树*/
    function selectResourceTree() {
        var treeId = $("#treeId").val();
        var resourceId = treeId > 0 ? treeId : 1;
        var url = ctx+"resource/selectResourceById/" + resourceId;
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
    $('input[type=radio][name=type]').change(function() {
        var menuType = $(event.target).val();
        if (menuType == "0") {
            $("#url").parents(".form-group").hide();
            $("#permission").parents(".form-group").hide();
            $("#icon").parents(".form-group").show();
            $("#description").parents(".form-group").hide();
        } else if (menuType == "1") {
            $("#url").parents(".form-group").show();
            $("#permission").parents(".form-group").show();
            $("#icon").parents(".form-group").hide();
            $("#description").parents(".form-group").show();
        } else if (menuType == "2") {
            $("#url").parents(".form-group").hide();
            $("#permission").parents(".form-group").show();
            $("#icon").parents(".form-group").hide();
            $("#description").parents(".form-group").show();
        }
    });
</script>
</body>
</html>